package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.FabiPublishListBean;
import com.sskj.b70.m.bean.HaiPageBean;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.m.http.JsonConverter;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.FabiSellListActivity;

import java.util.List;

import io.reactivex.Flowable;


public class FabiSellListPresenter extends BasePresenter<FabiSellListActivity> {

    public Flowable<List<FabiPublishListBean>> getData(int page, boolean isBuy,
                                                       String startTime, String endTime) {
        return httpService.getFabiPublishOrderList(page, isBuy, startTime, endTime)
                .converter(new JsonConverter<HttpData<HaiPageBean<FabiPublishListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(haiPageBeanHttpData -> haiPageBeanHttpData.getData().getRes());
    }

    public void cancelOrder(boolean isBuy, String id) {

        httpService.cancelFabiPublishOrder(isBuy, id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            mView.delete();
                        }
                    }
                });

    }
}

